cmake_minimum_required(VERSION 3.20)
project(qt_demo)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    set(CMAKE_PREFIX_PATH "/opt/Qt5.14.2/5.14.2/gcc_64/")
else()
    set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.14.2/5.14.2/mingw73_64")
endif()

set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations ")

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Widgets Gui PrintSupport REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets Gui PrintSupport REQUIRED)

message(STATUS 'QT_VERSION=${QT_VERSION_MAJOR}')
message(STATUS 'Qt_Path=${Qt${QT_VERSION_MAJOR}_DIR}')

include_directories(
        ${PROJECT_SOURCE_DIR}/include
        ${PROJECT_SOURCE_DIR}/third_party/qcustomplot
)

qt5_add_big_resources(PROJECT_SOURCES
        application.qrc
        )

set(QCUSTOMPLOT_SRC
        ${PROJECT_SOURCE_DIR}/third_party/qcustomplot/qcustomplot.h
        third_party/qcustomplot/qcustomplot.cpp
        )

add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/serial serial)

#add_executable(qt_demo src/main.cpp src/mainwindow.cpp include/mainwindow.h ${PROJECT_SOURCES})
add_executable(qt_demo chart/main.cpp chart/widget.cpp chart/widget.h chart/widget.ui ${QCUSTOMPLOT_SRC})
target_link_libraries(qt_demo
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::PrintSupport
        serial
        )
